/************************* 版本声明 *********************************
 *@since jdk1.5
 *@version 0.1
 ************************* 变更记录 *********************************
 *
 * 创建者：bijiqiang Email:bijiqiang@gmail.com   创建日期： 2010-12-7
 * 创建记录：创建类结构。
 *************************  描 述 *********************************
 * 
 ******************************************************************
 */
package com.realgodo.site.web.admin.adv;

import javax.annotation.Resource;

import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.convention.annotation.Results;
import org.springframework.context.annotation.Scope;
import org.springside.modules.orm.Page;

import com.realgodo.site.entity.site.Advertisement;
import com.realgodo.site.service.site.AdvertisementManager;
import com.realgodo.site.web.admin.AdminDefaultController;

@Scope("prototype")
@Results( { @Result(name = "toindex", type = "redirect", location = "${base}/admin/adv/") })
public class IndexController extends AdminDefaultController {

	private static final long serialVersionUID = 7545936754537692753L;

	@Resource
	private AdvertisementManager advertisementManager;

	private Advertisement advertisement;

	private Page<Advertisement> advertisementPage = new Page<Advertisement>(
			PAGE_SIZE);

	public String execute() {
		advertisementPage.setPageNo(advertisementManager.isParamNotNull(
				getParamMap(), Page.PAGE) ? Integer
				.valueOf((String) advertisementManager.getParamValue(
						getParamMap(), Page.PAGE)) : 1);// 查询页数
		this.advertisementPage = advertisementManager
				.findAdvertisements(advertisementPage);
		super.setPageInfo(advertisementPage);
		return SUCCESS;
	}

	public String add() {
		advertisement = (getId() != null) ? this.advertisementManager
				.get(getId()) : null;
		return "add";
	}

	public String save() {
		advertisement = (Advertisement) this.advertisementManager
				.saveMerge(advertisement);
		return "toindex";
	}

	/*************** getter and setter ***********************/
	public Advertisement getAdvertisement() {
		return advertisement;
	}

	public void setAdvertisement(Advertisement advertisement) {
		this.advertisement = advertisement;
	}

	public Page<Advertisement> getAdvertisementPage() {
		return advertisementPage;
	}

	public void setAdvertisementPage(Page<Advertisement> advertisementPage) {
		this.advertisementPage = advertisementPage;
	}

}
